package cn.chaohi.utils;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.UUID;

public class CommonUtil {
	
	/**
	 * redis中1号数据库
	 */
	public static final int DB_INDEX_1 = 1;

	/**
	 * 生成UUID
	 * 
	 * @return
	 */
	public static String get32UUID() {
		String uuid = UUID.randomUUID().toString().trim().replaceAll("-", "");
		return uuid;
	}

	/**
	 * 判断是否为Intger类型
	 * 
	 * @param temp
	 * @return
	 */
	public static boolean isInt(Object temp) {
		if (temp instanceof Integer)
			return true;
		else
			return false;
	}

	/**
	 * 数组转换为List（推荐使用）
	 * 
	 * @param arr
	 *            数组
	 * @return List
	 */
	@SuppressWarnings("rawtypes")
	public static List array2List2(Object[] arr) {
		List list = new ArrayList();
		if (arr == null)
			return list;
		list = Arrays.asList(arr);
		return list;
	}
	
	/**
	 * 
	 * @Title: 方法名称：getSixRandom   
	 * @Description: 获取6位随机数字
	 * @return 返回类型  ：int
	 */
	public static int getSixRandom(){
		int[] array = {0,1,2,3,4,5,6,7,8,9};
		Random rand = new Random();
		for (int i = 10; i > 1; i--) {
		    int index = rand.nextInt(i);
		    int tmp = array[index];
		    array[index] = array[i - 1];
		    array[i - 1] = tmp;
		}
		int result = 0;
		for(int i = 0; i < 6; i++)
		    result = result * 10 + array[i];
		return result;
	}
	
	public static int getOneRandom(){
		int[] array = {0,1,2,3,4,5,6,7,8,9};
		Random rand = new Random();
		for (int i = 10; i > 1; i--) {
		    int index = rand.nextInt(i);
		    int tmp = array[index];
		    array[index] = array[i - 1];
		    array[i - 1] = tmp;
		}
		int result = 0;
		for(int i = 0; i < 1; i++)
		    result = result * 10 + array[i];
		return result;
	}
	
	 private static final String STR_FORMAT = "0000"; 
	 public static String haoAddOne(String liuShuiHao){
	      Integer intHao = Integer.parseInt(liuShuiHao);
	      intHao++;
	      DecimalFormat df = new DecimalFormat(STR_FORMAT);
	      return df.format(intHao);
	 }

	public static String getBillNo() {
		return new StringBuilder("TX").append(System.currentTimeMillis()).append(getSixRandom()).toString();
	}
	
	public static void main(String[] args) {
		System.out.println(getBillNo());
	}
}
